/**
 *
 * Created by Pan,hongxue, 9/8/2011 7:14:40 PM
 *
 */

function validateVideoUrl(ori_url) 
{
	var html = download_page(ori_url,'GBK');
	var matches = html.match(/iid( = |:)(\d+)/);
	if (matches == null) {
	     // vid not found
	     return 'NotFoundVideo';
	}
	var dst_url = 'http://v2.tudou.com/v?it=' + matches[2] + '&refurl=' + ori_url;
	var xml_str = download_page(dst_url);
	var flv_string = parse_xml(xml_str,'a','f');
	var duration = parse_xml_attribute(xml_str,'/','time');
    var sb = [];
      
    sb.push(flv_string);
    if(sb.length){
       //matches = html.match(/<title>(.*?)<\/title>/);
       matches = html.match(/<title>([\s\S]*?)<\/title>/);
       if(matches){
    	   return 'success_title:' + encodeURIComponent(matches[1])
    	          + '\n video_urls:' + encodeURIComponent(sb)
    	          + '\n seconds:' + Math.round(parseInt(duration)/1000);
       }
    }
	return 'error:empty_path';
}

function js_get_media_url(ori_url) 
{
	var html = download_page(ori_url);
	var matches = html.match(/iid( = |:)(\d+)/);
	if (matches == null) {
		// vid not found
		return '';
	}
	var dst_url = 'http://v2.tudou.com/v?it=' + matches[2] + '&refurl=' + ori_url;
	var xml_str = download_page(dst_url);
	var flv_string = parse_xml(xml_str,'a','f');
        var sb = [];
      
        sb.push(flv_string);
	return sb;
}
